PRO MAIN_VI_Propress,inputfile,outputpath

  ;启动ENVI批处理模式
  COMPILE_OPT idl2
  ;恢复其核心的save文件
  ENVI, /RESTORE_BASE_SAVE_FILES
  ENVI_BATCH_INIT


  envi_open_file,inputfile,r_fid=fid_nor
  if(fid_nor eq -1)then return
  ENVI_FILE_QUERY,fid_nor,ns=ns_nor,nl=nl_nor,nb=nb_nor,dims=dims_nor
  map_info=envi_get_map_info(fid=fid_nor)
  pos_nor=lindgen(nb_nor)

  ;获取红波段和近红波段数据
  GreenBand = envi_get_data(fid=fid_nor,dims=dims_nor,pos=2)
  redBand = envi_get_data(fid=fid_nor,dims=dims_nor,pos=3)
  NirBand = envi_get_data(fid=fid_nor,dims=dims_nor,pos=4)
  MIRBand = envi_get_data(fid=fid_nor,dims=dims_nor,pos=5)

  ;NDVI计算
  NDVI = (NirBand/10000.0 - redBand/10000.0) / (NirBand/10000.0 + redBand/10000.0)

  ;NDVI异常值过滤
  waa=where(NDVI le -1)
  NDVI[waa]=-1
  wab=where(NDVI gt 1)
  NDVI[wab]=1


  ;保存NDVI计算结果
  strfilename = file_basename(inputfile,'.dat')
  out_name=outputpath+'\'+strfilename+'_NDVI.dat'
  ENVI_WRITE_ENVI_FILE,NDVI,out_name=out_name,map_info=map_info
  
  ;像元二分法 计算植被覆盖度   VFC=(NDVI-NDVImin)/(NDVImax-NDVImin)

  mina = 0.05
  maxa = 0.95

  wcc=where((NDVI gt -2),count)
  NDVIresultarr = fltarr(count)
  NDVIresultarr = NDVI[wcc]

  NDVIa=sort(NDVIresultarr)
  NDVIresultarr12 = NDVIresultarr[NDVIa]

  coutID1 = round(count*mina)
  coutID2 = round(count*maxa)

  NDVImin = NDVIresultarr12[coutID1-1]
  NDVImax = NDVIresultarr12[coutID2-1]

  ;  NDVImin = min(NDVI,/NAN)
  ;  NDVImax = max(NDVI,/NAN)

  VFC=(NDVI-NDVImin)/(NDVImax-NDVImin)

  ut_name=outputpath+'\'+strfilename+'_VFC.dat'
  ENVI_WRITE_ENVI_FILE,VFC,out_name=ut_name,map_info=map_info


  ENVI_FILE_MNG, ID = fid_nor, /REMOVE


END